package com.blast.comicsisland.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.NetworkImageView;
import com.blast.comicsisland.R;
import com.blast.comicsisland.model.rank.rankbody.Special;
import com.blast.comicsisland.utils.ImageLoaderUtil;

import java.util.List;

/**
 * Created by Android Studio
 * Author: hg
 * Date: 15/6/25
 * Email: 531057892@qq.com
 */
public class BookstoreRankAdapter extends BaseAdapter {

    private Context context;
    private List<Special> specials;

    public BookstoreRankAdapter(Context context, List<Special> specials) {
        this.context = context;
        this.specials = specials;
    }

    @Override
    public int getCount() {
        int ret = 0;
        if (specials != null) {
            ret = specials.size();
        }
        return ret;
    }

    @Override
    public Object getItem(int position) {
        Object ret = null;
        if (specials != null) {
            ret = specials.get(position);
        }
        return ret;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View ret = null;
        if (convertView != null) {
            ret = convertView;
        }else {
            ret = LayoutInflater.from(context).inflate(R.layout.item_bookstore_rank_list_view,parent,false);

        }
        HolderView holderView = (HolderView) ret.getTag();

        if (holderView == null){
            holderView = new HolderView();
            holderView.imageView = (NetworkImageView) ret.findViewById(R.id.item_bookstore_rank_list_image_view);
            holderView.titleTxt = (TextView) ret.findViewById(R.id.item_bookstore_rank_list_title_txt);
            holderView.contentTxt = (TextView) ret.findViewById(R.id.item_bookstore_rank_list_content_txt);
            ret.setTag(holderView);
        }

        Special special = specials.get(position);
        String description = special.getDescription();
        String name = special.getName();
        String coverUrl = special.getCoverurl();
        ImageLoaderUtil imageLoaderUtil = ImageLoaderUtil.getInstance();
        ImageLoader imageLoader = imageLoaderUtil.getImageLoader();

        holderView.imageView.setImageUrl(coverUrl,imageLoader);

        holderView.titleTxt.setText(name);
        holderView.contentTxt.setText(description);

        return ret;
    }


    class HolderView{

        private NetworkImageView imageView;
        private TextView titleTxt;
        private TextView contentTxt;
    }

}
